import java.io.*;
import java.net.*;
public class Serveur {
	public static void main(String argv[]) throws Exception
	{
		String phraseClient;
		String phraseMajuscule;
		boolean ok=true;
		int port=30456;
			
		ServerSocket socketEcoute = new ServerSocket(port);
		System.out.println("Serveur lance!! sur le port: "+port);
		while(ok)
		{
			//System.out.println("lol");
			Socket socketConnexion = socketEcoute.accept();
			BufferedReader entreeDepuisClient = new BufferedReader(new InputStreamReader(socketConnexion.getInputStream())); 
			System.out.println("machine connectee:"+socketConnexion.getInetAddress());
			
			System.out.println(socketConnexion.isConnected());
			
			DataOutputStream sortieVersClient = new DataOutputStream(socketConnexion.getOutputStream());
			phraseClient = entreeDepuisClient.readLine();
			System.out.println(phraseClient);
			phraseMajuscule = phraseClient.toUpperCase() + '\n';
			sortieVersClient.writeBytes(phraseMajuscule);
			
			if(phraseClient.equals("end serveur")){
				ok=false;
			}
			System.out.println(socketConnexion.isConnected());
		}
		

	}
}
